package com.coder4j.platform.mapper;

import com.coder4j.starter.mybatis.BaseMapper;
import com.coder4j.platform.entity.AuthApiEntity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;

import java.util.Arrays;
import java.util.List;

/**
 * 接口
 *
 * @author keller
 * @date 2024-05-07 18:10:10
 */
@Mapper
public interface AuthApiMapper extends BaseMapper<AuthApiEntity> {
    /**
     * 默认查询条件
     *
     * @return
     */
    @Override
    default List<String> defaultCondition() {
        return Arrays.asList(" <if test = 'createId!=null'> AND create_id=#{createId} </if>",
                " <if test = 'updateId!=null'> AND update_id=#{updateId} </if>",
                " <if test = 'isDeleted!=null'> AND is_deleted=#{isDeleted} </if>",
                " <if test = 'name!=null'> AND name=#{name} </if>",
                " <if test = 'appName!=null'> AND app_name=#{appName} </if>",
                this.baseLikeCondition("controllerName" ),
                " <if test = 'methodName!=null'> AND method_name=#{methodName} </if>",
                " <if test = 'url!=null'> AND url=#{url} </if>",
                " <if test = 'signatureCode!=null'> AND signature_code=#{signatureCode} </if>",
                " <if test = 'description!=null'> AND description=#{description} </if>",
                " <if test = 'useDataScope!=null'> AND use_data_scope=#{useDataScope} </if>");
    }

    /**
     * 删除应用下的所有API
     *
     * @param appName 应用名
     * @return
     */
    @Delete({"DELETE FROM auth_api WHERE app_name=#{appName}"})
    int deleteByAppName(String appName);
}
